/* 
 * File:   InputDevice.h
 * Copyright (C) 2008, 2009
 *		Sergio Padrino Recio (PadrinatoR)
 *
 * Created on 8 de septiembre de 2008, 19:41
 *
 * This file is part of BombProject.
 * 
 * BombProject is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
   
 * BombProject is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with BombProject.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _INPUTDEVICE_H
#define	_INPUTDEVICE_H

#include <SDL/SDL.h>

/**
 * Enumeration type that describes every type of input device:<br>
 * <b>DEVICE_NULL</b>: none.<br>
 * <b>DEVICE_KEYBOARD</b>: keyboard.<br>
 * <b>DEVICE_PAD</b>: digital pad.<br>
 * ...
 */
enum DeviceType {
	DEVICE_NULL = -1,
	DEVICE_KEYBOARD,
	DEVICE_PAD
};

/**
 * Struct that will contain information about a button and its device: the button code, the device type and the device index.
 * @see DeviceType, InputDevice
 */
typedef struct _DeviceButtonInfo {
	Uint16 button_code;
	DeviceType device_type;
	Uint16 device_index;
} DeviceButtonInfo;

/**
 * Struct which represents the state of a button: if it is recently pressed, if it's not pressed anymore, and if it's just pressed.
 * @see InputDevice
 */
typedef struct _ButtonState {
	Uint8 button_down;
	Uint8 button_up;
	Uint8 button_held;
} ButtonState;

/**
 * Represents an input device.
 * @see Keyboard
 */
class InputDevice {
protected:
	ButtonState* mBuffer;
	Uint16 mNumButtons;
	DeviceType mType;
	Uint16 mIndex;
	
public:
	InputDevice(Uint16 index);
	~InputDevice();
	
	virtual void init() = 0;
	
	virtual ButtonState* getLinkFromPressedButton(DeviceButtonInfo& button_info) = 0;
	virtual ButtonState* getLinkFromButtonCode(Uint16 button_code) = 0;
	
	virtual void update() = 0;
	
	virtual void destroy() = 0;
	
	DeviceType getDeviceType();
	Uint16 getDeviceIndex();
};

#endif	/* _INPUTDEVICE_H */

